package org.springblade.modules.system.controller;

import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.modules.system.entity.Doctor;
import org.springblade.modules.system.service.DoctorService;
import org.springblade.modules.system.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/doctor")
public class DoctorController extends BladeController {

	@Autowired
	private DoctorService doctorService;

	@ResponseBody
	@RequestMapping(value = "/openDoctorTable", method = RequestMethod.POST)
	public HashMap<String, Object> openDoctorTable(String doctorName, String createTimeMax, String createTimeMin, int pageSize, int currentPage) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		PageBounds<Doctor> pageBounds = null;
		try {
			pageBounds = doctorService.openDoctorTable(doctorName, createTimeMax, createTimeMin, currentPage, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
		}
		result.put("data", pageBounds);
		return result;
	}

	/**
	 * 根据id获取实体
	 */
	@ResponseBody
	@RequestMapping(value = "/findById", method = RequestMethod.POST)
	public HashMap<String, Object> findById(Integer id) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		Doctor doctor = doctorService.findById(id);
		result.put("doctor", doctor);
		return result;
	}

	/**
	 * 获取全部信息
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAllDoctor", method = RequestMethod.POST)
	public HashMap<String, Object> selectAllDoctor() {
		HashMap<String, Object> result = new HashMap<String, Object>();
		List<Doctor> doctor = doctorService.selectAllDoctor();
		result.put("data", doctor);
		return result;
	}

	/**
	 * 添加
	 */
	@ResponseBody
	@RequestMapping(value = "/addDoctor", method = RequestMethod.POST)
	public HashMap<String, Object> addDoctor(Doctor doctor) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		doctor.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		doctorService.addDoctor(doctor);
		return result;
	}

	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping(value = "/updateDoctor", method = RequestMethod.POST)
	public HashMap<String, Object> updateDoctor(Doctor doctor) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		doctorService.updateDoctor(doctor);
		return result;
	}

	/**
	 * 通过id删除
	 */
	@ResponseBody
	@RequestMapping(value = "/deleteDoctorById", method = RequestMethod.POST)
	public HashMap<String, Object> deleteDoctorById(Integer id) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		// DoctorService.deleteDoctorById(Arrays.asList(id));
		doctorService.deleteDoctorById(id);
		return result;
	}

	/**
	 * 通过id多删除
	 *
	 * @param @return
	 * @Title: delStudentById
	 */
	@ResponseBody
	@RequestMapping(value = "/deleteDoctorByIds", method = RequestMethod.POST)
	public HashMap<String, Object> deleteDoctorByIds(Integer[] ids) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		doctorService.deleteDoctorByIds(Arrays.asList(ids));
		return result;
	}
}
